﻿@model OrderMasterModel

@{
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@{
    var viewModel = Model ?? new OrderMasterModel();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
    Dictionary<string, string> labelDicTypeName = ReleaseBiz.GetLabelTypeNameDic();
}
<form id="S_Form" action="@Url.Action("doSave", "OrderMaster")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" style="width:50%">
                <h5>
                    @ViewBag.Title
                </h5>
                <input type="hidden" value="@viewModel.view_Order.order_id" name="order_id" />
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">订单号</td>
            <td>
                @viewModel.view_Order.order_NO
            </td>

            <td class="tableleft">下单用户</td>
            <td>
                @viewModel.view_Order.account_mobile  代购编号：@viewModel.view_Order.replace_buyer_NO
            </td>
        </tr>
        <tr>
            <td class="tableleft">订单金额</td>
            <td>
                <div id="show_total_money" style="display:block">
                    <info>  @viewModel.view_Order.total_money </info>

                    @if (viewModel.view_Order.order_status == (int)OrderStatus.WaitPay)
                    {
                        <a href="@Url.Action("editprice", "OrderMaster", new { id = viewModel.view_Order.order_id})">修改价格</a>
                    }

                </div>
            </td>

            <td class="tableleft">订单状态</td>
            <td>
                @(MyEnumHelper.GetEnumItemDescription<OrderStatus>(viewModel.view_Order.order_status.Value))
                @if (!(viewModel.view_Order.is_confirm_payed == 1)
                && (viewModel.view_Order.is_succ == 1))
                {
                    <button type="button" class="btn btn-primary" id="btn_confirmpay">确认已支付</button>
                }
                @if (viewModel.view_Order.is_confirm_payed == 1)
                {
                    <info class="green">&nbsp;已人工确认支付</info>
                }
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">下单时间</td>
            <td>@viewModel.view_Order.create_time.ToString(1)</td>

            <td width="10%" class="tableleft">支付信息</td>
            <td>
                <div>
                    支付方式：@(MyEnumHelper.GetEnumItemDescription<PayType>(viewModel.view_Order.pay_type.Value))
                </div>
                @if (viewModel.view_Order.is_succ.Value == (int)PaySucc.Paid)
                {
                    <div class="green">已支付 支付时间：@viewModel.view_Order.pay_succ_time.ToString(1)</div>

                    if (viewModel.view_Order.pay_type.Value == (int)PayType.UnderLine)
                    {
                        Html.RenderPartial(Url.Content("~/Views/Common/ImgsOne.cshtml"), viewModel.view_Order);
                    }
                }
                @if (viewModel.view_Order.is_succ.Value == (int)PaySucc.NotPay)
                {
                    <span class="red">
                        未支付
                        @if (viewModel.view_Order.order_status.Value == (int)OrderStatus.Cancel)
                        {
                            <span>支付已关闭</span>
                        }
                        else if (viewModel.view_Order.order_status.Value == (int)OrderStatus.WaitPay)
                        {
                            if (viewModel.view_Order.pay_end_time.HasValue)
                            {
                                <span>支付关闭时间：@viewModel.view_Order.pay_end_time.ToString(1)</span>
                            }

                            Html.RenderPartial(Url.Content("~/Views/Common/ImgsOne.cshtml"), viewModel.view_Order);

                            <button type="button" class="btn btn-primary" id="btn_setpay">设为已支付</button>
                            <button type="button" class="btn btn-primary" id="btn_cancelorder">关闭订单</button>
                        }
                    </span>
                }
            </td>
        </tr>
        <tr>
            <td class="tableleft">发货状态<em></em></td>
            <td>
                @{
                    switch (viewModel.view_Order.is_send.Value)
                    {
                        case (int)IsSend.NotSend:
                            <div class="red">
                                @(MyEnumHelper.GetEnumItemDescription<IsSend>(viewModel.view_Order.is_send.Value))
                                <button type="button" class="btn btn-primary btn_setsended1" id="btn_setsended1">设为已发货</button>
                                <button type="button" class="btn btn-primary" id="btn_setsended2">设为自提取货</button>
                            </div>
                            break;
                        case (int)IsSend.Sended:
                            @:<div class="green">@(MyEnumHelper.GetEnumItemDescription<IsSend>(viewModel.view_Order.is_send.Value)) 发货时间：@viewModel.view_Order.send_time.ToString(1)</div>
                            if (viewModel.view_Order.order_status.Value == (int)OrderStatus.PaySucc)
                            {
                                <button type="button" class="btn btn-primary" id="btn_confirm">确认收货</button>
                            }
                            break;
                        case (int)IsSend.GetUseSelf:
                            @:<div class="green">@(MyEnumHelper.GetEnumItemDescription<IsSend>(viewModel.view_Order.is_send.Value)) 设置时间：@viewModel.view_Order.send_time.ToString(1)</div>
                            if (viewModel.view_Order.order_status.Value == (int)OrderStatus.PaySucc)
                            {
                                <button type="button" class="btn btn-primary" id="btn_confirm">确认收货</button>
                            }
                            break;
                    }
                }
            </td>
            <td class="tableleft">发票信息<em></em></td>
            <td>
                @switch (viewModel.view_Order.is_invoice.Value)
                {
                    case 0:
                        @:<div>不需要发票</div>
                        break;
                    case 1:
                        if (viewModel.aDZ_OrderInvoiceRel == null)
                        {
                            <div class="red">发票资料还未上传</div>
                        }
                        else
                        {
                            <div>
                                <div class="thumb-item-wrap">
                                    <a href="javacript:void(0);" class="img-wrap">
                                        <img class="thumb-img" src="@ImageFileBiz.GetImg(viewModel.aDZ_OrderInvoiceRel.invoice_img, "small")" style="width: 100px;margin:auto;">
                                    </a>
                                </div>
                            </div>

                            if (viewModel.aDZ_OrderInvoiceRel.is_ready == 1)
                            {
                                <div class="green">发票已开 开票时间：@viewModel.aDZ_OrderInvoiceRel.invoice_date.ToString(1)</div>
                            }
                            if (viewModel.aDZ_OrderInvoiceRel.is_ready == 0)
                            {
                                <div class="red">发票未开 &nbsp;<button type="button" class="btn btn-primary" id="btn_setInvoiced">设为已开票</button></div>
                            }
                        }
                        @*@:<div>发票类型：@(MyEnumHelper.GetEnumItemDescription<InvoiceType>(viewModel.ordreInvoice.aDZ_UserInvoice.invoice_type.Value))</div>
                            @:<div>开票金额：@viewModel.view_Order.total_money</div>
                            @:<div>发票抬头：@viewModel.ordreInvoice.aDZ_UserInvoice.invoice_title</div>
                            @:<div>纳税人识别号：@viewModel.ordreInvoice.aDZ_UserInvoice.taxpayer_ID</div>
                            @:<div>发票内容：@viewModel.view_Order.invoice_content</div>*@
                        break;
                }
            </td>
        </tr>
        <tr>
            <td>收货信息</td>
            <td>
                <div style="float:left;width:100%;display:block;">收货人：<input type="text" name="receiver" value="@viewModel.view_Order.receiver" />  </div>
                <div style="float:left;width:100%;display:block;">手机号：<input type="text" name="receiver_telephone" value="@viewModel.aDZ_OrderAddress.receiver_telephone" /> </div>
                <div style="float:left;width:100%;display:block;">收货地址：<input type="text" style="width:350px;" name="address_desc" value="@viewModel.aDZ_OrderAddress.address_desc" /> </div>
                <div style="float:left;width:100%;display:block;"><info style="float:left;">快递公司：</info> @viewModel.aDZ_OrderAddress.express_com</div>
                <div style="float:left;width:100%;display:block;">快递单号：@viewModel.aDZ_OrderAddress.express_NO</div>
            </td>
            <td class="tableleft">备注信息</td>
            <td colspan="3"><textarea name="remark" style="width:80%;" maxlength="2500" placeholder="用户未填备注" cols="4">@viewModel.view_Order.remark</textarea></td>

        </tr>
        <tr>
            <td class="tableleft"></td>
            <td colspan="3">

                <button type="submit" class="btn btn-primary">保存</button> &nbsp;&nbsp;
                <button type="button" backpageid="ordermaster/ordermasterlist" class="btn btn-success" name="backid" id="backid">返回</button>
                &nbsp;&nbsp;<button type="button" onclick="$(this).attr('disabled', true);document.location.href = '/dayin/pdf?print_type=fahuotongzhi&id=@viewModel.view_Order.order_id'" class="btn btn-success">打印发货通知单</button>
                &nbsp;&nbsp;<button type="button" onclick="$(this).attr('disabled', true);document.location.href='/dayin/pdf?print_type=caigoudan&id=@viewModel.view_Order.order_id'" class="btn btn-success">打印采购单</button>
                &nbsp;&nbsp;<button type="button" onclick="$(this).attr('disabled', true);document.location.href='/dayin/pdf?print_type=xiaoshouhetong&id=@viewModel.view_Order.order_id'" class="btn btn-success">打印销售合同</button>
                &nbsp;&nbsp;<button type="button" onclick="$(this).attr('disabled', true);document.location.href='/dayin/chukudan?id=@viewModel.view_Order.order_id'" class="btn btn-success">打印出库单</button>
                &nbsp;&nbsp;<button type="button" onclick="$(this).attr('disabled', true);document.location.href='/dayin/rukudan?id=@viewModel.view_Order.order_id'" class="btn btn-success">打印入库单</button>
            </td>
        </tr>
    </table>
</form>
<div id="content" class="hide">
    <form id="J_Form" class="form-horizontal">
        <div class="row">
            <div class="control-group span8">
                <label class="control-label"><s>*</s>学校名称：</label>
                <div class="controls">
                    <input name="school" type="text" data-rules="{required:true}" class="input-normal control-text">
                </div>
            </div>
            <div class="control-group span8">
                <label class="control-label"><s>*</s>学生类型：</label>
                <div class="controls">
                    <select data-rules="{required:true}" name="type" class="input-normal">
                        <option value="">请选择</option>
                        <option value="zou">走读</option>
                        <option value="zhu">住校</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span15 ">
                <label class="control-label">在校日期：</label>
                <div id="range" class="controls bui-form-group" data-rules="{dateRange : true}">
                    <input name="enter" class="calendar" type="text"><label>&nbsp;-&nbsp;</label><input name="outter" class="calendar" type="text">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span15">
                <label class="control-label">备注：</label>
                <div class="controls control-row4">
                    <textarea name="memo" class="input-large" type="text"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<h5>商品列表</h5>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th style="width:70px">图片</th>
            <th>料号</th>
            <th>品牌</th>
            <th>分类</th>
            <th>供应商</th>
            <th>物料来源</th>
            <th>板块</th>
            <th>库存价格</th>
            <th>订购数量</th>
            <th>单位</th>
            <th>供货单价</th>
            <th>佣金比例</th>
            <th>销售单价</th>
            <th>订单总价</th>
            <th>币种</th>
            <th>佣金金额</th>
            <th></th>
        </tr>
    </thead>
    @if (viewModel.orderGoods != null && viewModel.orderGoods.Count != 0)
    {
        int index = 0;
        foreach (var orderGoods in viewModel.orderGoods)
        {
            var m = orderGoods.views_Goods;
            var goodsdetail = orderGoods.aDZ_OrderDetails;
            index++;
<tr class="@HtmlPagerHelper.TrClass(index)">
    <td>
        @{
            var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id);
            foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
            {
                <a href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
            }
        }
    </td>
    <td>@m.MPN</td>
    <td>@m.brand_name</td>
    <td>@m.category_name</td>
    <td>@m.supplier_name</td>
    <td>@m.material_source_name</td>
    <td>
        <div>@labelDicTypeName[m.label_type.ToString()]</div>
    </td>
    <td>@m.price</td>
    <td>@goodsdetail.amount</td>
    <td>@m.goods_unit</td>

    <td>@(m.supply_price == null ? "-" : m.supply_price.Value.ToString("f5"))</td>
    <td>@(m.supply_price == null ? "-" : ((goodsdetail.sell_price - m.supply_price) / goodsdetail.sell_price).Value.ToString("f5"))</td>

    <td>@((goodsdetail.sell_price).ToString("f5"))</td>

    <td>@goodsdetail.total_money.Value.ToString("f2")</td>
    <td>
        @switch (m.currency_type)
        {
            case 0:
                @:<div class="">人民币</div>
                break;
            case 1:
                @:<div class="red">美金</div>
                break;
        }
    </td>
    <td>@(m.supply_price == null ? "-" : ((goodsdetail.sell_price - m.supply_price) * goodsdetail.amount).Value.ToString("f5"))</td>
    <td>
        <a href="@Url.Action("detailInfo", "product", new { id = m.goods_id})">查看</a>
    </td>
</tr>
        }
    }
</table>

<h5>订单日志</h5>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th>序号</th>
            <th>操作内容</th>
            <th>时间</th>
            <th>操作人</th>
        </tr>
    </thead>
    @if (viewModel.view_Order.order_id > 0)
    {
        var list = dbcontext.ADZ_OrderMasterLog.Where(t => t.order_id == viewModel.view_Order.order_id).OrderByDescending(t => t.id);
        int index = 0;
        foreach (var m in list)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>@m.id</td>
                <td style="white-space: pre-line;">@m.opmsg</td>
                <td>@m.create_time.ToString(1)</td>
                <td>@m.op_user</td>
            </tr>
        }
    }
</table>



<script>
    BUI.use('bui/select', function (Select) {
        var b = '@viewModel.aDZ_OrderAddress.express_com';

        $.post('@Url.Action("getexpress", "common")', function (result) {
            var suggest = new Select.Suggest({
                render: '#div_express_com',
                name: 'express_com',
                data: result
            });
            suggest.render();
            $("input[name='express_com']").val(b);
            $("input[name='express_com']").attr("autocomplete", "off");

            $("#div_Mask").hide();
        });
    });

    var id = @viewModel.view_Order.order_id;
    var cancelButton =
        {
            text: '取消',
            elCls: 'button',
            handler: function () {
                this.close();
            }
        };
    reloadHandler = function ()
    {
        //document.execCommand('Refresh');
        //location.replace(location.href);
        window.location.reload();
    }
    $("#btn_setpay").click(function () {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该订单设为已支付吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("setpay", "OrderMaster")";

                      parameter = new FormData($('#S_Form')[0]);

                      $.ajax({
                          type:'POST',
                          url: url,
                          data: parameter,
                          contentType: false,
                          processData: false,
                          mimeType: "multipart/form-data",
                          success: function (result) {
                              ShowActionResult(JSON.parse(result), reloadHandler);
                          }
                      }
                      );
                      //$.post(url, parameter, function (result) {
                      //    ShowActionResult(result, reloadHandler);
                      //});
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    });

    $("#btn_cancelorder").click(function () {
        BUI.Message.Show({
            title: '提示',
            msg: '订单取消后将不能继续支付！',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("cancelorder", "OrderMaster")";
                      parameter = {
                          id: id
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    });




        $("#btn_confirm").click(function () {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将此订单确认收货吗？',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("confirmOrder", "OrderMaster")";
                      parameter = {
                          id: id
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    });

    $("#btn_setInvoiced").click(function () {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将此订单设为已开票吗？',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("setInvoiced", "OrderMaster")";
                      parameter = {
                          id: id
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    });
        $("#btn_confirmpay").click(function () {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将此订单设为已确认支付吗？',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("setConfirmpay", "OrderMaster")";
                      parameter = {
                          id: id
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
        });

        BUI.use('bui/overlay', function (overlay) {
            $(function () {
                var rules = {
                    'receiver': { required: true },
                    'receiver_telephone': { required: true, isMobile: true },
                    'address_desc': { required: true }
                };
                var validator = $('#S_Form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    rules: rules,
                    submitHandler: function (form) {
                        $(form).ajaxSubmit(function (result) {
                            ShowActionResult(result, reloadHandler);
                        });
                    }
                });

            });


        });

</script>
<style>
    #div_Mask {
        text-align: center;
        line-height: 100px;
        font-weight: bold
    }

    #J_Form {
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,.4);
        position: absolute;
        z-index: 1000;
        top: 0;
        left: 0;
        color: #000;
    }
</style>
<div id="div_Mask">
    <form id="J_Form">
        <table class="table table-bordered definewidth m10 " style="width:800px;top:200px;background-color:#fff">
            <tr>
                <th colspan="2">
                    设置快递信息
                </th>
            </tr>
            <tr>
                <td style="text-align:right">
                    快递公司：
                </td>
                <td>
                    <div id="div_express_com" style="float:left;"></div>
                </td>
            </tr>
            <tr>
                <td style="text-align:right">
                    快递单号：
                </td>
                <td>
                    <input type="text" name="express_NO" id="express_NO" value="@viewModel.aDZ_OrderAddress.express_NO" />
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <button type="button" class="btn btn-primary" id="btn_saveexp">保存</button> &nbsp;&nbsp;
                    <button type="button" class="btn btn-success" id="btn_cancel">取消</button>
                </td>
            </tr>
        </table>
    </form>
</div>
<script>
    $("#btn_setsended1").click(function () {
        $("#div_Mask").show();
    });
    $("#btn_cancel").click(function () {
        $("#div_Mask").hide();
    });
    $("#btn_saveexp").click(function () {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将此订单设为已发货吗？',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("setSended", "OrderMaster")";
                      parameter = {
                          id: id,
                          express_com:$("#express_com").val(),
                          express_NO: $("#express_NO").val(),
                          is_send:1
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                          $("#div_Mask").hide();
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    });
    $("#btn_setsended2").click(function () {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将此订单设为自提取货吗？',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("setSended", "OrderMaster")";
                      parameter = {
                          id: id,
                          express_com:$("#express_com").val(),
                          express_NO: $("#express_NO").val(),
                          is_send:2
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                          $("#div_Mask").hide();
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    });

</script>